        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>DistanceProxy class / box2d_html Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d_html" data-type="DistanceProxy">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d_html.html">box2d_html</a> &rsaquo; <a href="../box2d_html/DistanceProxy.html">DistanceProxy</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>DistanceProxy</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>A distance proxy is used by the GJK algorithm. It encapsulates any shape.</p>
<pre class="source">
class DistanceProxy {
  final List&lt;Vector&gt; vertices;
  int count;
  num radius;

  /**
   * Constructs a new DistanceProxy.
   */
  DistanceProxy() :
    vertices = new List&lt;Vector&gt;(Settings.MAX_POLYGON_VERTICES),
    count = 0,
    radius = 0 {

      for(int i = 0; i &lt; vertices.length; ++i)
        vertices[i] = new Vector();
    }

  /**
   * Initialize the proxy using the given shape. The shape
   * must remain in scope while the proxy is in use.
   */
  void setFromShape(shape) {
    // If the shape is a circle...
    if (shape.type == ShapeType.CIRCLE) {
      vertices[0].setFrom(shape.position);
      count = 1;
      radius = shape.radius;

      // If the shape is a polygon...
    } else if (shape.type == ShapeType.POLYGON) {
      count = shape.vertexCount;
      radius = shape.radius;
      for(int i = 0; i &lt; count; i++) {
        vertices[i].setFrom(shape.vertices[i]);
      }
    } else {
      // Should always be a circle or a polygon.
      assert(false);
    }
  }

  /**
   * Get the supporting vertex index in the given direction.
   */
  int getSupport(Vector direction) {
    int bestIndex = 0;
    num bestValue = Vector.dot(vertices[0], direction);
    for (int i = 1; i &lt; count; ++i) {
      num value = Vector.dot(vertices[i], direction);
      if(value &gt; bestValue) {
        bestIndex = i;
        bestValue = value;
      }
    }

    return bestIndex;
  }

  /**
   * Get the supporting vertex in the given direction.
   */
  Vector getSupportVertex(Vector direction) =&gt; vertices[getSupport(direction)];
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="DistanceProxy">
<button class="show-code">Code</button>
new <strong>DistanceProxy</strong>() <a class="anchor-link" href="#DistanceProxy"
              title="Permalink to DistanceProxy.DistanceProxy">#</a></h4>
<div class="doc">
<p>Constructs a new DistanceProxy.</p>
<pre class="source">
DistanceProxy() :
  vertices = new List&lt;Vector&gt;(Settings.MAX_POLYGON_VERTICES),
  count = 0,
  radius = 0 {

    for(int i = 0; i &lt; vertices.length; ++i)
      vertices[i] = new Vector();
  }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="count">
<button class="show-code">Code</button>
int         <strong>count</strong> <a class="anchor-link"
            href="#count"
            title="Permalink to DistanceProxy.count">#</a>
        </h4>
        <div class="doc">
<pre class="source">
int count;
</pre>
</div>
</div>
<div class="field"><h4 id="radius">
<button class="show-code">Code</button>
num         <strong>radius</strong> <a class="anchor-link"
            href="#radius"
            title="Permalink to DistanceProxy.radius">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num radius;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="runtimeType">
<button class="show-code">Code</button>
final Type         <strong>runtimeType</strong> <a class="anchor-link"
            href="#runtimeType"
            title="Permalink to DistanceProxy.runtimeType">#</a>
        </h4>
        <div class="inherited-from">inherited from Object </div><div class="doc">
<p>A representation of the runtime type of the object.</p>
<pre class="source">
external Type get runtimeType;
</pre>
</div>
</div>
<div class="field"><h4 id="vertices">
<button class="show-code">Code</button>
final List&lt;<a href="../box2d_html/Vector.html">Vector</a>&gt;         <strong>vertices</strong> <a class="anchor-link"
            href="#vertices"
            title="Permalink to DistanceProxy.vertices">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final List&lt;Vector&gt; vertices;
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method inherited"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to DistanceProxy.operator ==">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>The equality operator.</p>
<p>The default behavior for all <code>Object</code>s is to return true if and
only if <code>this</code> and 
<span class="param">other</span> are the same object.</p>
<p>If a subclass overrides the equality operator it should override
the <code>hashCode</code> method as well to maintain consistency.</p>
<pre class="source">
bool operator ==(other) =&gt; identical(this, other);
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="DistanceProxy">
<button class="show-code">Code</button>
new <strong>DistanceProxy</strong>() <a class="anchor-link" href="#DistanceProxy"
              title="Permalink to DistanceProxy.DistanceProxy">#</a></h4>
<div class="doc">
<p>Constructs a new DistanceProxy.</p>
<pre class="source">
DistanceProxy() :
  vertices = new List&lt;Vector&gt;(Settings.MAX_POLYGON_VERTICES),
  count = 0,
  radius = 0 {

    for(int i = 0; i &lt; vertices.length; ++i)
      vertices[i] = new Vector();
  }
</pre>
</div>
</div>
<div class="method"><h4 id="getSupport">
<button class="show-code">Code</button>
int <strong>getSupport</strong>(<a href="../box2d_html/Vector.html">Vector</a> direction) <a class="anchor-link" href="#getSupport"
              title="Permalink to DistanceProxy.getSupport">#</a></h4>
<div class="doc">
<p>Get the supporting vertex index in the given direction.</p>
<pre class="source">
int getSupport(Vector direction) {
  int bestIndex = 0;
  num bestValue = Vector.dot(vertices[0], direction);
  for (int i = 1; i &lt; count; ++i) {
    num value = Vector.dot(vertices[i], direction);
    if(value &gt; bestValue) {
      bestIndex = i;
      bestValue = value;
    }
  }

  return bestIndex;
}
</pre>
</div>
</div>
<div class="method"><h4 id="getSupportVertex">
<button class="show-code">Code</button>
<a href="../box2d_html/Vector.html">Vector</a> <strong>getSupportVertex</strong>(<a href="../box2d_html/Vector.html">Vector</a> direction) <a class="anchor-link" href="#getSupportVertex"
              title="Permalink to DistanceProxy.getSupportVertex">#</a></h4>
<div class="doc">
<p>Get the supporting vertex in the given direction.</p>
<pre class="source">
Vector getSupportVertex(Vector direction) =&gt; vertices[getSupport(direction)];
</pre>
</div>
</div>
<div class="method inherited"><h4 id="hashCode">
<button class="show-code">Code</button>
int <strong>hashCode</strong>() <a class="anchor-link" href="#hashCode"
              title="Permalink to DistanceProxy.hashCode">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Get a hash code for this object.</p>
<p>All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator <code>==</code>. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.</p>
<p>If a subclass overrides <code>hashCode</code> it should override the
equality operator as well to maintain consistency.</p>
<pre class="source">
external int hashCode();
</pre>
</div>
</div>
<div class="method inherited"><h4 id="noSuchMethod">
<button class="show-code">Code</button>
<strong>noSuchMethod</strong>(String name, List args) <a class="anchor-link" href="#noSuchMethod"
              title="Permalink to DistanceProxy.noSuchMethod">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p><code>noSuchMethod</code> is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to <code>noSuchMethod</code>. If <code>noSuchMethod</code>
returns a value, that value becomes the result of the original
invocation.</p>
<p>The default behavior of <code>noSuchMethod</code> is to throw a
<code>noSuchMethodError</code>.</p>
<pre class="source">
external Dynamic noSuchMethod(String name, List args);
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Object">
<button class="show-code">Code</button>
const <strong>Object</strong>() <a class="anchor-link" href="#Object"
              title="Permalink to DistanceProxy.Object">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Creates a new <code>Object</code> instance.</p>
<p><code>Object</code> instances have no meaningful state, and are only useful
through their identity. An <code>Object</code> instance is equal to itself
only.</p>
<pre class="source">
const Object();
</pre>
</div>
</div>
<div class="method"><h4 id="setFromShape">
<button class="show-code">Code</button>
void <strong>setFromShape</strong>(shape) <a class="anchor-link" href="#setFromShape"
              title="Permalink to DistanceProxy.setFromShape">#</a></h4>
<div class="doc">
<p>Initialize the proxy using the given shape. The shape
must remain in scope while the proxy is in use.</p>
<pre class="source">
void setFromShape(shape) {
  // If the shape is a circle...
  if (shape.type == ShapeType.CIRCLE) {
    vertices[0].setFrom(shape.position);
    count = 1;
    radius = shape.radius;

    // If the shape is a polygon...
  } else if (shape.type == ShapeType.POLYGON) {
    count = shape.vertexCount;
    radius = shape.radius;
    for(int i = 0; i &lt; count; i++) {
      vertices[i].setFrom(shape.vertices[i]);
    }
  } else {
    // Should always be a circle or a polygon.
    assert(false);
  }
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to DistanceProxy.toString">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Returns a string representation of this object.</p>
<pre class="source">
external String toString();
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
